let checkAge = (rule, value, callback) => {
  if (value !== '' && !/^(1[0-9][0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(value)) {
    callback(new Error('请输入正确的手机号'))
  } else {
    callback()
  }
}
let isTelPhone = (rule, value, callback) => {
  if (value !== '' && !/^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/.test(value)) {
    callback(new Error('请输入正确的传真号'))
  } else {
    callback()
  }
}
let isTelPhones = (rule, value, callback) => {
  if (value !== '' && !/^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/.test(value)) {
    callback(new Error('请输入正确的座机号'))
  } else {
    callback()
  }
}
let isQQAccount = (rule, value, callback) => {
  if (value !== '' && !/^[1-9][0-9]{4,10}$/.test(value)) {
    callback(new Error('请输入正确的QQ号'))
  } else {
    callback()
  }
}
let isWeChatAccount = (rule, value, callback) => {
  if (value !== '' && !/^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/.test(value)) {
    callback(new Error('请输入正确的微信号'))
  } else {
    callback()
  }
}
//配置正则

export let validcodeName = (rule, value, callback) => {
  let reg = /bus_[A-Za-z][A-Za-z]*/
  if (!reg.test(value)) {
    callback(new Error('账号必须是bus_开头'))
  } else {
    callback()
  }
}

//菜单页面普通菜单正则校验
let menuRules = {
  sort: [{ type: 'number', message: '序号必须为数字', trigger: 'blur' }],
  name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
  pid: [{ required: true, message: '请输入上级菜单', trigger: 'blur' }],
  code: [{ required: true, message: '请输入菜单编码', trigger: 'blur' }],
  routeUrl: [{ required: true, message: '请输入路由地址', trigger: 'blur' }],
  comments: [{ required: true, message: '请输入别名', trigger: 'blur' }],
  isDynamic: [{ required: true, message: '请选择动态菜单类型', trigger: 'blur' }]
}
//菜单页面按钮菜单正则校验
let menuButtonRules = {
  sort: [{ type: 'number', message: '序号必须为数字', trigger: 'blur' }],
  name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
  pid: [{ required: true, message: '请输入上级菜单', trigger: 'blur' }],
  code: [{ required: true, message: '请输入菜单编码', trigger: 'blur' }],
  routeUrl: [{ required: true, message: '请输入路由地址', trigger: 'blur' }],
  isFunctionType: [{ required: true, message: '请选择动态按钮类型', trigger: 'blur' }],
  buttonType: [{ required: true, message: '请选择动态按钮功能类型', trigger: 'blur' }]
}
//新建用户正则校验
let userRules = {
  name: [{ required: true, message: '请输入供应商名称', trigger: 'blur' }],
  businessType: [{ required: true, message: '请输入经营类型', trigger: 'blur' }]
  
}
//用户管理重置密码
let Resetpassword = {
  oldPassword: [{ required: true, message: '请输入密码', trigger: 'blur' }],
  oldPassword2: [{ required: true, message: '请输入密码', trigger: 'blur' }],
  newPassword: [
    {
      required: true,
      message: '请输入密码',
      trigger: 'blur'
    }
  ]
}
//感知源接入列表 验证配置
let rolesRules = {
  ip: [{ required: true, message: '请输入感知源ip', trigger: 'blur' }],
  cameraId: [{ required: true, message: '请输入感知源id', trigger: 'blur' }],
  port: [{ required: true, message: '请输入感知源端口', trigger: 'blur' }],
  userName: [{ required: true, message: '请输入感知源账户', trigger: 'blur' }],
  passWord: [{ required: true, message: '请输入感知源密码', trigger: 'blur' }],
  osTenantId: [{ required: true, message: '请输入租户ID', trigger: 'blur' }],
  type: [{ required: true, message: '请选择类型', trigger: 'blur' }]
}
//招标信息录入必填项
let configForm = {
  noticeTitle: [{ required: true, message: '请输入公告标题', trigger: 'blur' }],
  projectName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
  noticeType: [{ required: true, message: '请输入公告类型', trigger: 'blur' }],
  type: [{ required: true, message: '请输入招标类型', trigger: 'blur' }],
  projectCode: [{ required: true, message: '请输入项目编号', trigger: 'blur' }],
  noticeContent: [{ required: true, message: '请输入公告内容', trigger: 'blur' }],
}

//登录页面表单验证
let loginRules = {
  username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
}
let englishName = (rule, value, callback) => {
  if (value === '' || !/^[a-zA-Z_]+$/.test(value)) {
    callback(new Error('英文名只支持大小写字母及下划线'))
  } else {
    callback()
  }
}
//表单数据字典验证规则
let reg = {
  //新建表单验证
  form: {
    name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    pname: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    sort: [{ type: 'number', message: '序号必须为数字', trigger: 'blur' }],
    englishName: [
      { required: true, message: '请输入英文名', trigger: 'blur' },
      { validator: englishName, trigger: 'blur' }
    ]
  },
  //字段验证
  filedReg: {
    fieldName: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
    fieldEnglishName: [
      { required: true, message: '英文名称不能为空', trigger: 'blur' },
      {
        validator: englishName,
        message: '英文名只支持大小写字母及下划线',
        trigger: 'blur'
      }
    ],
    viewName: [{ required: true, message: '所属视图名称不能为空', trigger: 'blur' }],
    viewFieldName: [{ required: true, message: '视图字段名不能为空', trigger: 'blur' }]
  },
  //子表验证
  tableSon: {
    tableName: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
    tableEnglishName: [
      { required: true, message: '英文名不能为空', trigger: 'blur' },
      { validator: englishName, trigger: 'blur' }
    ],
    sort: [{ type: 'number', message: '序号必须为数字', trigger: 'blur' }]
  },
  //字典验证
  filedClass: {
    name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    pname: [{ required: true, message: '上级字典项不能为空', trigger: 'blur' }],
    sort: [{ type: 'number', message: '序号必须为数字', trigger: 'blur' }],
    englishName: [
      { required: true, message: '请输入英文名', trigger: 'blur' },
      { validator: englishName, trigger: 'blur' }
    ]
  },
  //字典值验证
  filedClassvalue: {
    name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    value: [{ required: true, message: '请输入字典值', trigger: 'blur' }],
    sort: [{ type: 'number', message: '序号必须为数字', trigger: 'blur' }]
  }
}
export {
  checkAge,
  isTelPhone,
  isTelPhones,
  isQQAccount,
  isWeChatAccount,
  reg,
  menuRules,
  menuButtonRules,
  userRules,
  Resetpassword,
  rolesRules,
  configForm,
 
  loginRules
}
